{% extends 'app01/base_backend.html' %}
{% block person_manage %}
    <a class="navbar-brand" href="#">我的web资源</a>
{% endblock %}
{% block all_li %}
    <li role="presentation">
        <a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">我的web资源</a>
    </li>
    <li role="presentation" class="active">
        <a href="{% url 'app01_backend' %}" style="color: #337ab7">返回个人管理</a></li>
{% endblock %}

{% block all_content %}
    {% block caogao %}
        <div class="panel panel-default">
            <div class="panel-heading">我的web资源</div>
            <div class="panel-body">
                <div class="row">
                    <div class="col-md-12 ">
                        <table class="table table-hover table-striped">
                            <thead>
                            <tr>
                                <th>资源名字</th>
                                <th>资源描述</th>
                                <th>等级</th>
                                <th>原代码</th>
                                <th>操作</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {% for source in c_page %}
                                <tr>
                                    <td>{{ source.name }}</td>
                                    <td>
                                        <a href="/app01/site/{{ source.uploader.username }}/source_detail/{{ source.pk }}/?pk={{ source.pk }}&url={{ request.get_full_path }}">{{ source.descn }}</a>
                                    </td>
                                    <td>{{ source.get_level_display }}</td>
                                    <td><a href="/app01/show_web_source?pk={{ source.pk }}">下载</a></td>
                                    <td><a href="/app01/editer/source?source_id={{ source.pk }}&url={{ request.get_full_path }}">修改</a></td>
                                    <td><a href="#" class="del_suorce_class" del_id="{{ source.pk }}">删除</a></td>
                                </tr>

                            {% endfor %}


                            </tbody>
                        </table>


                    </div>
                </div>
            </div>
        </div>



        {# 分页显示 #}
        <div class="pager">
            <nav aria-label="Page navigation">
                <ul class="pagination">
                    {{ page_html }}
                </ul>
            </nav>
        </div>
    {% endblock %}

{% endblock %}
{% block js %}
    <script>
        if ('{{ request.user.username }}'.slice(0, 3) === '512') {
            $('#p_for_a').html('<a href="/app01/manage_student/" class="list-group-item">学生管理</a>')
            $('#role_for').html('角色：<br><a href="#">老师</a>')
        }


        if ('{{ request.user.username }}'.slice(0, 3) === '312') {

            $('#set_person_id').html('<p>班级：<input type="text" id="stu_class" class="form-control" value="{{ request.user.stu_class }}"></p>')
            $('#role_for').html('角色：<br><a href="#">学生</a>')
        }
        //删除资源的ajax请求
        $('.del_suorce_class').click(function () {
            let op = confirm('是否确认删除？')
            let source_id = $(this).attr('del_id')
            if (op === true) {
                $.ajax({
                    url: '',
                    type: 'post',
                    data: {'op': op, 'del_id': source_id},
                    success: function (attr) {
                        if (attr.code === 100) {
                            alert(attr.msg)
                            window.location.reload()
                        } else {
                            alert(attrmsg)
                        }

                    }
                })
            }

        })

        //文件上传的ajax请求
        $("#up_btn_id").click(function () {
            let formObj = new FormData()
            formObj.append('file', $('#up_file_id')[0].files[0])
            formObj.append('filename', $('#file_name_id').val())
            formObj.append('desc', $('#file_desc_id').val())
            let radio_chioce = $('input[name="share"]:checked').val();
            formObj.append('share', radio_chioce)

            $.ajax({
                url: "/app01/upload_file/",
                type: 'post',
                data: formObj,
                contentType: false,
                processData: false,
                success: function (array) {
                    if (array.code === 1000) {
                        alert(array.msg0)
                        parent.location.href = array.url
                    } else if (array.code === 2000) {
                        //用户输入不正确的提示
                        $('#p1').next().text(array.msg1)
                        $('#p2').next().text(array.msg2)
                        $('#p3').next().text(array.msg3)
                    } else {
                        alert(array.msg0)
                    }

                }
            })


        });

    </script>
{% endblock %}